//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类.demo1AND20;

public class demo4 {
    public demo4() {
    }

    public static void main(String[] args) {
        int[] num1 = new int[]{1, 2};
        int[] num2 = new int[]{3, 4};
        System.out.println(a(num1, num2));
    }

    public static double a(int[] num1, int[] num2) {
        int[] arr = new int[num1.length + num2.length];
        int k = 0;
        int i = 0;
        int j = 0;

        while(i <= num1.length - 1 && j <= num2.length - 1) {
            if (num1[i] < num2[j]) {
                arr[k] = num1[i];
                ++k;
                ++i;
            } else {
                if (k > arr.length / 2 + 1) {
                    break;
                }

                arr[k] = num2[j];
                ++k;
                ++j;
            }
        }

        if (i != num1.length) {
            for(int z = i; z < num1.length; ++z) {
                arr[k] = num1[z];
                ++k;
                if (k > arr.length / 2 + 1) {
                    break;
                }
            }
        } else if (j != num2.length) {
            for(int z = j; z < num2.length; ++z) {
                arr[k] = num2[z];
                ++k;
            }
        }

        return arr.length % 2 == 0 ? (double)(arr[arr.length / 2 - 1] + arr[arr.length / 2]) / (double)2.0F : (double)arr[arr.length / 2];
    }
}
